<template>
	<view>
		<view  class="wrap bgw">
			<view class="tops p30">
				<u-search :show-action="true" action-text="搜索" :animation="true" :clearabled="true" placeholder="搜索关键词" @search="searchs"
				 @custom="searchs" v-model="keyword"></u-search>
			</view>
			<view class="contents p30">
				<view v-for="(v,i) in data" :key="i" class="lists">
					<p @tap="GoMarket(v)" class="p1 one">
						# {{v.name}} #
					</p>
					<p @tap="GoMarketSet(v)" class="p2 ">
						编辑
					</p>
				</view>
			</view>
		</view>
		<view v-if="data == '' &&  keyword == '' " class=" dataNone">
			<image src="../../static/image/huati.png" mode=""></image>
			<p>暂未创建集市 ~ </p>
			<u-button @tap="GoCreateMarket()" :ripple="true" shape="circle" type="success">
				去创建
			</u-button>
		</view>
		<view v-if="data == '' &&  keyword != '' " class=" dataNone">
			<image src="../../static/image/huati.png" mode=""></image>
			<p>暂未创建该集市 ~ </p>
			<u-button @tap="GoCreateMarket()" :ripple="true" shape="circle" type="success">
				去创建
			</u-button>
		</view>
	</view>

</template>

<script>
	import {
		myMaketList
	} from '../../api/api.js'
	export default {
		data() {
			return {
				keyword: '',
				pageNumber: 1,
				pageSize: 20,
				stops: 0,
				data: [],
				noneState:0,
			};
		},
		onShow() {
			this.data = []
			this.pageNumber = 1
			this.stops = 0
			this.init()
		},
		methods: {
			GoCreateMarket(){
				this.$navigateTo('../CreateMarket/CreateMarket')
			},
			searchs() {
				this.data = []
				this.pageNumber = 1
				this.stops = 0
				this.init()
			},
			GoMarket(v) {
				this.$navigateTo('../ji/ji?id=' + v.id)
			},
			GoMarketSet(v) {
				uni.setStorageSync('marketSets', v)
				this.$navigateTo('../CreateMarket/CreateMarket')
			},
			async init() {
				let parameret = {
					keyword: this.keyword,
					pageable: {
						pageNumber: this.pageNumber,
						pageSize: this.pageSize
					}
				}
				let data = await myMaketList(parameret)
				data = data.data.content
				if (data.length != this.pageSize) {
					this.stops = 1
				} 
				this.data = [...this.data, ...data]
				this.pageNumber = this.pageNumber + 1
			}
		}
	}
</script>

<style lang="less" scoped>
	@import './index';
</style>
